const express = require('express');
const app = express();
const cors = require('cors');
//允许跨域白名单
var whitelist = ['http://lv666.top', 'http://www.lv666.top'];
var corsOptions = {
    origin: function (origin, callback) {
        console.log(origin)
        if (whitelist.indexOf(origin) !== -1) {
            callback(null, true)
        } else {
            callback(new Error('Not allowed by CORS'))
        }
    }
}
app.use(cors(corsOptions));
//处理from表单过来的数据
app.use(express.urlencoded({
    extended: true
}))
//处理JSON数据
app.use(express.json());

app.use('/api/label', require('./api/label'));
app.use('/api/data', require('./api/project_and_wz'));
app.use('/api/comment', require('./api/comments'))

//端口号
const port = 8841;
app.listen(port, () => {
    console.log(`http://localhost:${port}`);
});